<?php

/**
 * Contains a class to display /event.php.
 *
 * PHP Version 5
 *
 * @category BuyLocal
 * @package  BuyLocal
 * @author   Kevin Fodness <kevin.fodness@gmail.com>
 * @author   Mike Pennisi <mpennisi@andrew.cmu.edu>
 * @author   Aaron Ryden <aryden@gmail.com>
 * @author   Spencer Hakim <hakims@rpi.edu>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://code.google.com/p/buylocalopensourcerensselaer/
 */
 
/** @uses valueOf For safe handling of arrays. */
require_once 'function_valueof.php';
 
/**
 * A class to display /event.php.
 *
 * @category BuyLocal
 * @package  BuyLocal
 * @author   Kevin Fodness <kevin.fodness@gmail.com>
 * @author   Mike Pennisi <mpennisi@andrew.cmu.edu>
 * @author   Aaron Ryden <aryden@gmail.com>
 * @author   Spencer Hakim <hakims@rpi.edu>
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
 * @link     http://code.google.com/p/buylocalopensourcerensselaer/
 */ 
class PageEvent extends Page
{
    /**
     * Variable to contain the active event as an Event object.
     *
     * @access public
     * @var object
     */
    public $event;
    
    /**
     * Constructor function.  Calls the parent constructor and sets the title.
     */
    public function __construct()
    {
        parent::__construct();
        if (valueOf($_GET, 'eventid') != '') {
            $this->event = $this->db->getEventById(
                valueOf($_GET, 'eventid'), 
                $this->user->zip->latitude,
                $this->user->zip->longitude,
                true
            );

            $countries = $this->db->getCountries();
            $this->event->country = $countries[$this->event->country - 1]['name'];
        }
        parent::setTitle('Event Details');
    }
    
    /**
     * Function to print the event information block.
     *
     * @access private
     * @return null
     */
    private function _printEventInfo()
    {
        $map = new Map($this->event);
        echo ' <ul class="stores">', "\n";
        $this->event->printListItemFull(
            $this->db->isEventOwner($this->user->id, $this->event)
            || $this->user->role == R_ADMIN
        );
        echo ' </ul>', "\n";
        $map->display();
    }
    
    /**
     * Function to display the page.
     *
     * @access public
     * @return null
     */
    public function display()
    {
        parent::printHeader();
        if ($this->event != null) {
            $this->_printEventInfo();
        } else {
            echo 'No event selected', "\n";
        }
        parent::printFooter();
    }
}

?>